from typing import List, Tuple
from threading import Thread

from .scraper import TrackShipmentsScraper
from utils import (
    get_links_for_parsing,
    get_random_account
)


def main() -> None:

    previous_account: Tuple[str, str] = None
    old_threads: List[Thread] = []
    links_for_parsing: List[str] = get_links_for_parsing()

    for link_for_parsing in links_for_parsing:
        account: Tuple[str, str] = get_random_account(previous_account)
        thread: Thread = Thread(
            target=TrackShipmentsScraper().start,
            args=(link_for_parsing, account)
        )
        thread.start()
        old_threads.append(thread)
        previous_account = account

    _ = [thread.join() for thread in old_threads]
